/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
define(["ojs/ojcore","jquery","promise","ojs/ojcomponentcore"],function(a,g){a.Fd={};o_("PullToRefreshUtils",a.Fd,a);a.Fd.DLa=function(b,c,d){var e,f,h,k,l,m,r,t,s,q,p,n,u,v;a.Fd.rka(b);e=g(document.createElement("div")).addClass("oj-pulltorefresh-outer");a.Fd.LCa(e,c,d);f=g(document.createElement("div")).addClass("oj-pulltorefresh-panel");e.append(f);h=g(b);h.prepend(e);h.on("touchstart.pulltorefresh",function(b){null==g.data(f[0],"data-pullstart")&&0===h[0].scrollTop&&(a.Fd.M9(b,f,d),s=f.find(".oj-pulltorefresh-icon"),
0<s.length&&(q=s.parent().outerHeight(!0)),d&&!isNaN(d.threshold)&&(l=parseInt(d.threshold,10)),l=isNaN(l)?f.outerHeight(!0):Math.max(0,Math.min(l,f.outerHeight(!0))),f.css("height",0),f.removeClass("oj-pulltorefresh-transition"),g.data(f[0],"data-pullstart",b.originalEvent.touches[0].clientY),g.data(f[0],"data-pullstart-horiz",b.originalEvent.touches[0].clientX),k=!0)}).on("touchmove.pulltorefresh",function(b){m=g.data(f[0],"data-pullstart");if(null!=m&&(r=b.originalEvent.touches[0].clientY-parseInt(m,
10),!(0>r)))if(b.preventDefault(),null!=g.data(f[0],"data-loading"))f.css("height",Math.max(r,l));else{if(k&&(k=!1,t=b.originalEvent.touches[0].clientX-parseInt(g.data(f[0],"data-pullstart-horiz"),10),Math.abs(t)>r))return;f.css("height",r);a.Fd.dJ(b,"pull",f,r);null!=s&&0<s.length&&(p=g.data(f[0],"data-lasticonclass"),null!=p&&s.removeClass(p),u=10*Math.round(r/l*10),100<=u?(v="oj-pulltorefresh-icon-full",n=a.va.F("oj-pullToRefresh.titleIconFull")):(v="oj-pulltorefresh-icon-"+u+"-percent",n=a.va.F("oj-pullToRefresh.titleIcon"+
u+"percent")),s.addClass(v),s.attr("title",n),g.data(f[0],"data-lasticonclass",v),a.Fd.CEa(f,r>q))}}).on("touchcancel.pulltorefresh",function(){a.Fd.wo(f)}).on("touchend.pulltorefresh",function(b){m=g.data(f[0],"data-pullstart");null!=m&&null==g.data(f[0],"data-loading")&&(f.outerHeight()<l?(f.addClass("oj-pulltorefresh-transition").css("height",0),a.Fd.wo(f)):a.Fd.N9(b,f,c))})};o_("PullToRefreshUtils.setupPullToRefresh",a.Fd.DLa,a);a.Fd.M9=function(b,c,d){var e,f;a.Fd.dJ(b,"pull",c,0);0==c.children().length&&
(d&&(e=d.primaryText,f=d.secondaryText),a.Fd.Sra(c,e,f));c.prev().text(a.va.F("oj-pullToRefresh.ariaRefreshingLink"));c.css("height","auto");g.data(c[0],"data-panelheight",c.outerHeight())};a.Fd.N9=function(b,c,d){var e,f,h,k;e=g.data(c[0],"data-panelheight");c.addClass("oj-pulltorefresh-transition").css("height",e);a.Fd.dJ(b,"release",c,e);g.data(c[0],"data-loading",!0);f=c.find(".oj-pulltorefresh-icon");0<f.length&&(h=g.data(c[0],"data-lasticonclass"),null!=h&&f.removeClass(h),f.addClass("oj-pulltorefresh-icon-full"));
d().then(function(){k=function(){a.Fd.dJ(b,"complete",c,e);a.Fd.wo(c);c.off("transitionend",k);c.prev().text("")};c.prev().text(a.va.F("oj-pullToRefresh.ariaRefreshCompleteLink"));c.prev().prev().css("position","");c.on("transitionend",k);c.css("height",0)})};a.Fd.rka=function(a){g(a).children(".oj-pulltorefresh-outer").remove();g(a).off(".pulltorefresh")};o_("PullToRefreshUtils.tearDownPullToRefresh",a.Fd.rka,a);a.Fd.dJ=function(a,c,d,e){c=g.Event("oj"+c);c.originalEvent=a;d.trigger(c,{content:d,
distance:e})};a.Fd.Sra=function(a,c,d){var e,f;a.addClass("oj-pulltorefresh-content").attr("aria-hidden","true");e=g(document.createElement("div"));e.addClass("oj-pulltorefresh-icon oj-pulltorefresh-icon-initial");f=g(document.createElement("div"));f.addClass("oj-pulltorefresh-icon-container");f.append(e);g.data(a[0],"data-lasticonclass","oj-pulltorefresh-icon-initial");a.append(f);null!=c&&(c=g(document.createElement("div")).addClass("oj-pulltorefresh-primary-text").text(c),a.append(c),null!=d&&
(d=g(document.createElement("div")).addClass("oj-pulltorefresh-secondary-text").text(d),a.append(d)))};a.Fd.CEa=function(a,c){var d,e;d=a.find(".oj-pulltorefresh-primary-text");e=a.find(".oj-pulltorefresh-secondary-text");c?(d&&d.show(),e&&e.show()):(d&&d.hide(),e&&e.hide())};a.Fd.LCa=function(b,c,d){var e,f,h;e=g(document.createElement("a"));e.text(a.va.F("oj-pullToRefresh.ariaRefreshLink"));e.addClass("oj-helper-hidden-accessible").attr("href","#").focus(function(){e.css("position","static")}).blur(function(a){null!=
a.relatedTarget&&e.css("position","")}).click(function(e){f=b.children().last();a.Fd.M9(e,f,d);a.Fd.N9(e,f,c);c()});h=g(document.createElement("div"));h.addClass("oj-helper-hidden-accessible").attr("aria-live","polite");b.append(e);b.append(h)};a.Fd.wo=function(a){g.removeData(a[0],"data-pullstart");g.removeData(a[0],"data-pullstart-horiz");g.removeData(a[0],"data-loading");0<a.find(".oj-pulltorefresh-icon").length&&a.empty()}});